/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.mwas.proteana.math.factorials;

import java.math.BigDecimal;

/**
 *
 * @author loskov
 */
public class FactorialSimple extends Factorial {

    public FactorialSimple(int n) {
        super(n);
    }

    public FactorialSimple(BigDecimal n) {
        super(n);
    }

    @Override
    protected BigDecimal calculate() {
        if (base.equals(BigDecimal.ZERO) || base.equals(BigDecimal.ONE)) {
            result = BigDecimal.ONE;
        } else if (base.intValue() < 200) {
            BigDecimal temp;
            result = BigDecimal.ONE;
            for(int i = base.intValue(); i > 0; i--) {
                temp = new BigDecimal(i);
                result = result.multiply(temp);
            }
        } else {
            logger.error("Factorial base to high for this method");
            throw new ArithmeticException("Factorial base to high for this method");
        }

        return result;
    }

    @Override
    public BigDecimal getResult() {
        return result;
    }

}
